/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Controller.CoreServlet;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import Model.ObjectBean.RequestBean.*;
import Model.BeanUltility.*;
import Model.DataUltility.*;
/**
 *
 * @author chickencake1
 */
public class registerServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //Init -----------
        request.setCharacterEncoding("UTF-8");
        Data_Access access = new Data_Access();
        BeanRegister register = new BeanRegister();
        response.setContentType("text/html;charset=UTF-8");
        // populate inform to Bean from client 
        PopulateBean.populateBeans(register, request);
       // Push down DB
       String []account_data={register.getUsername(),register.getPassword()};
       String []personal_data={register.getUsername(),register.getFirstname(),register.getLastname(),
       register.getEmail(),register.getAddress(),register.getSex(),register.getPhonenumber(),
       register.getCity(),register.getBirthday(),register.getPayment_style(),register.getQuestion(),
       register.getAnswer()};
       
       PrintWriter out = response.getWriter();
       for(int i=0;i<personal_data.length;i++)
       {
           out.println(personal_data[i]);
       }
       //access.insertInformation("login_account", account_data);
       access.insertInformation("personal_info", personal_data);
       
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
    

}
